package com.yili.oa.dao.extend;

import com.yili.oa.models.Admin;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.math.BigDecimal;

public interface AdminExtendMapper {

    @Select({
            "select",
            "id, username, password, name, create_time, parent, last_login_time, is_admin, ",
            "state, userRole, money, level_id, experience, history_money, available_commission",
            "from t_admins",
            "where username = #{id,jdbcType=VARCHAR} for update"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.INTEGER, id=true),
            @Result(column="username", property="username", jdbcType=JdbcType.CHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.BIGINT),
            @Result(column="parent", property="parent", jdbcType=JdbcType.CHAR),
            @Result(column="last_login_time", property="lastLoginTime", jdbcType=JdbcType.BIGINT),
            @Result(column="is_admin", property="isAdmin", jdbcType=JdbcType.INTEGER),
            @Result(column="state", property="state", jdbcType=JdbcType.INTEGER),
            @Result(column="userRole", property="userrole", jdbcType=JdbcType.VARCHAR),
            @Result(column="money", property="money", jdbcType=JdbcType.DECIMAL),
            @Result(column="level_id", property="levelId", jdbcType=JdbcType.BIGINT),
            @Result(column="experience", property="experience", jdbcType=JdbcType.BIGINT),
            @Result(column="history_money", property="historyMoney", jdbcType=JdbcType.DECIMAL),
            @Result(column="available_commission", property="availableCommission", jdbcType=JdbcType.VARCHAR)
    })
    Admin selectByUserName(String username);

    @Update({
            "update t_admins set available_commission = #{availableCommission,jdbcType=VARCHAR},version = version+1 where id = #{id,jdbcType=INTEGER} and version = #{version,jdbcType=BIGINT}"
    })
    int updateByIdAndVersion(Admin admin);

    @Update({
            "update t_admins set experience = experience+1 where username = #{userId,jdbcType=INTEGER}"
    })
    int addExperience(String userId);



}
